//
//  InfoTextInputView.m
//  CreditHub
//
//  Created by chenglang on 2024/9/21.
//

#import "InfoTextInputView.h"
#import "MultipleChoicePopUpVC.h"
#import "CHPopUpViewController.h"
#import "CityListPopupViewController.h"

@implementation InfoTextInputView
- (void)awakeFromNib{
    [super awakeFromNib];
    self.textFileld.delegate = self;
}
- (instancetype)init{
    self = [super init];
    if(self){
        
        self.textFileld.delegate = self;
    }
    return self;
}

- (void)setDicInfo:(NSMutableDictionary *)dicInfo{
    _dicInfo = dicInfo;
    
    self.textFileld.text = dicInfo[@"sudden"];
    self.buttonSelect.hidden = YES;
    NSString *type = CHString(dicInfo[@"kick"]);
    if([type isEqualToString:@"bottom"] || [type isEqualToString:@"heundressed"]){
        self.buttonSelect.hidden = NO;
    }else{
        [dicInfo setValue:dicInfo[@"sudden"] forKey:@"spindly"];
    }
    if( [type isEqualToString:@"heundressed"]){
       
        [dicInfo setValue:dicInfo[@"sudden"] forKey:@"spindly"];
    }
    if([CHString(dicInfo[@"stolen"]) isEqualToString:@"1"]){
        self.textFileld.keyboardType = UIKeyboardTypeNumberPad;
    }
}


- (IBAction)clickSelect:(id)sender {
    
    NSString *type = CHString(self.dicInfo[@"kick"]);
    if([type isEqualToString:@"bottom"]){
        
        NSArray *arrSelect = [NSArray arrayWithArray:self.dicInfo[@"harder"]];
        NSMutableArray *values = [NSMutableArray array];
        for (NSDictionary *dic in arrSelect) {
            [values addObject:dic[@"wouldwonder"]];
        }
        
        __weak typeof(self) weakSelf = self;
        MultipleChoicePopUpVC *vc = [[MultipleChoicePopUpVC alloc] init];
        vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
        vc.dataSource =values;
        vc.selectBlock = ^(NSInteger row) {
            NSDictionary *dicSelect = arrSelect[row];
            [weakSelf.dicInfo setValue:dicSelect[@"spindly"] forKey:@"spindly"];
            weakSelf.textFileld.text = dicSelect[@"wouldwonder"];
        };
        [[UIView xhl_getTopViewController] presentViewController:vc animated:YES completion:^{
            
        }];
    }else if([type isEqualToString:@"heundressed"]){
      
        __weak typeof(self) weakSelf = self;
        CityListPopupViewController *vc = [[CityListPopupViewController alloc] init];
        vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
        vc.selectBlock = ^(NSString * _Nonnull address) {
            [weakSelf.dicInfo setValue:address forKey:@"spindly"];
            weakSelf.textFileld.text = address;
        };
        [[UIView xhl_getTopViewController] presentViewController:vc animated:YES completion:^{
            
        }];
    }
    
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
  
    [self.dicInfo setValue:textField.text forKey:@"spindly"];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
